import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';
import { constantRouterMap } from '@/config/router.config';
import { BasicRawLayout } from '@/layouts';

const routes: Array<RouteRecordRaw> = [
    ...constantRouterMap,
];

const router = createRouter({
    history: createWebHistory('/'),
    routes
});

// 添加路由守卫，处理子应用路由
router.beforeEach((to, from, next) => {
    // 如果是访问子应用路由，直接放行
    if (to.path.startsWith('/app1/') || to.path.startsWith('/app2/') || to.path.startsWith('/app3/')) {
        next();
    } else {
        // 主应用路由正常处理
        next();
    }
});

export default router;
